<template>
  <div class="seller" ref="seller">
    <div class="seller-content">
      <div class="overview">
        <h1 class="title">{{seller.name}}</h1>
        <div class="desc border-1px">
          <star :size="36" :score="seller.score"></star>
          <span class="text">({{seller.ratingCount}})</span>
          <span class="text">月售{{seller.sellCount}}单</span>
        </div>
        <ul class="remark">
          <li class="block">
            <h2>起送价</h2>
            <div class="content">
              <span class="stress">{{seller.minPrice}}</span>元
            </div>
          </li>
          <li class="block">
            <h2>商家配送</h2>
            <div class="content">
              <span class="stress">{{seller.deliveryPrice}}</span>元
            </div>
          </li>
          <li class="block">
            <h2>平均配送时间</h2>
            <div class="content">
              <span class="stress">{{seller.deliveryTime}}</span>分钟
            </div>
          </li>
        </ul>
        <div class="favorite" @click="toggleFavorite">
          <span class="icon-favorite"></span>
          <span class="text">{{favoriteText}}</span>
        </div>
      </div>
      <split></split>
    </div>
  </div>
</template>
<script>
import star from 'components/star/star'
import split from 'components/split/split'
import {saveToLocal, loadFromLocal} from 'common/js/store'
export default {
  // props: {
  //   seller: {
  //     type: Object
  //   }
  // },
  data () {
    return {
      seller: {},
      favorite: false
    }
  },
  // 或者在这个页面请求数据 然后赋值操作
  computed: {
    favoriteText () {
      return this.favorite ? '已收藏' : '收藏'
    }
  },
  created () {
    this.$http.get('api/seller').then((res) => {
      if (res.data.errno === 0) {
        this.seller = res.data.data
        this.favorite = loadFromLocal(this.seller.id, 'favorite', false)
      }
    })
  },
  methods: {
    toggleFavorite () {
      this.favorite = !this.favorite
      saveToLocal(this.seller.id, 'favorite', this.favorite)
    }
  },
  components: {
    star,
    split
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus">
  .seller
    position absolute
    top 174px
    bottom 0
    left 0
    width 100%
    overflow hidden
    .overview
      position relative
      padding 18px
    .title
      margin-bottom 8px
      line-height 14px
      color rgb(7, 17, 27)
      font-size 14px
    .desc
      padding-bottom 18px
      border-1px(rgba(7, 17, 27, 0.1))
      font-size 0
      .star
        display inline-block
        margin-right 8px
        vertical-align top
      .text
        display inline-block
        margin-right 12px
        line-height 18px
        vertical-align top
        font-size 10px
        color rgb(77, 85, 93)
    .remark
      display flex
      padding-top 18px
      .block
        flex  1
        text-align center
        border-right 1px solid rgba(7, 17, 27, 0.1)
        &:last-child
          border none
        h2
          margin-bottom 4px
          line-height 10px
          font-size 10px
          color: rgb(147, 153, 159)
        .content
          line-height: 24px
          font-size: 10px
          color: rgb(7, 17, 27)
          .stress
            font-size: 24px
    .favorite
      position absolute
      width 50px
      right 11px
      top 18px
      text-align center
      .icon-favorite
        display block
        margin-bottom 4px
        line-height 24px
        font-size 24px
        color #d4d6d9
        &.active
          color: rgb(240, 20, 20)
      .text
        line-height 10px
        font-size: 10px
        color: rgb(77, 85, 93)
</style>
